<!--
    随机昵称API

-->
<template>
  <div class="container">

    <!--  面包屑导航 -->
    <nav aria-label="breadcrumb">
      <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="/onlinetool/#/">首页</a></li>
        <li class="breadcrumb-item"><a href="#">休闲娱乐</a></li>
        <li class="breadcrumb-item active" aria-current="page">随机昵称</li>
      </ol>
    </nav>

    <!--  头部卡片  -->
    <div class="card border-primary ">
      <!--  放在 .card 里面的标签默认宽度会占满父元素宽度, 所以 a 标签应该放在 .card-body 里面-->
      <div class="card-header bg-info">随机昵称</div>
      <div class="card-body ">
        <h5 class="card-title text-primary">随机生成一个昵称，快快拿去使用吧~</h5>
        <p class="card-text"></p>
        <button type="button" @click="getNickName" class="btn btn-outline-success">生成昵称</button>

        <!--  旋转提示组件  -->
        <div class="spinner-border text-success ml-5" role="status">
          <span class="sr-only">Loading...</span>
        </div>
      </div>
    </div>

    <!--  结果内容展示：使用卡片-->
    <div class="card mt-3">
      <div class="card-body text-center text-warning font-weight-bold lead">
        {{ nickname }}
      </div>
    </div>

  </div>
</template>

<script>
  export default {
    name: 'NickName',
    data() {
      return {
        nickname: ""
      }
    },
    methods: {
      async getNickName() {
        this.$(".spinner-border").css("display", "inline-block");

        const result = await this.$http.get("http://hn216.api.yesapi.cn/?s=App.Common_Nickname.RandOne&app_key=F8464B49D9036F3477747B3C17B26690");
        console.log(result);
        this.nickname = result.data.data.nickname;
        if (this.content !== "") {
          this.$(".spinner-border").css("display", "none");
        }
      }
    }
  }
</script>

<style scoped>
  .spinner-border {
    display: none;
  }
</style>
